package com.example.spring.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * Created by Administrator on 2017-9-13.
 */

@RestController
@RequestMapping(value = "/test/cookie")
public class HttpSessionController {

    @RequestMapping(value = "/cookieTest")
    public String httpSession(@RequestParam("browser") String browser, HttpServletRequest request, HttpServletResponse response, HttpSession session){

        Object sessionBrowser = session.getAttribute("browser");
        if(sessionBrowser == null){
            System.out.println("sessionBrowser is null");
            session.setAttribute("browser",browser);
        }else{
            System.out.println("sessionBrowser is not null:"+sessionBrowser.toString());
        }

        Cookie[] cookies = request.getCookies();
        for(Cookie cookie : cookies){
            System.out.println("cookie name == " + cookie.getName() + ",cookie.value="+cookie.getValue());
        }
        return "111111111111111";
    }

}
